package cn.fuxi2022.auth.controller;

import cn.fuxi2022.auth.service.GroupStudentService;
import cn.fuxi2022.core.utils.PageUtils;
import cn.fuxi2022.model.empty.auth.GroupStudent;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 社员表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-09-20 20:10:51
 */
@RestController
@RequestMapping("/groupStudent")
public class GroupStudentController {
    @Autowired
    private GroupStudentService groupStudentService;

    /**
     * 根据公众号openid获取学生信息
     */
    @RequestMapping("/getStudentByOpenidGz/{openidGz}")
    public GroupStudent getStudentByOpenidGz(@PathVariable("openidGz") String openidGz) {
        LambdaQueryWrapper<GroupStudent> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupStudent::getOpenidGz,openidGz);
        return groupStudentService.getOne(wrapper);
    }

    // ---------------------------------------------------------------

    /**
     * 获取学生信息
     */
    @RequestMapping("/getStudent/{id}")
    public GroupStudent getStudent(@PathVariable("id") String id) {
        return groupStudentService.getById(id);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        return groupStudentService.queryPage(params);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") String id) {
        groupStudentService.removeById(id);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public void update(@RequestBody GroupStudent groupStudent) {
        groupStudentService.updateById(groupStudent);
    }
    // ----------------------------------------------------------------
}
